package com.xky.example_student.utils;

import org.springframework.util.DigestUtils;

/**
 * 密码更新工具类
 * 用于将明文密码转换为MD5格式
 */
public class PasswordUpdateTool {
    
    public static void main(String[] args) {
        // 常见密码的MD5值
        System.out.println("=== 常见密码的MD5值 ===");
        System.out.println("123456 -> " + DigestUtils.md5DigestAsHex("123456".getBytes()));
        System.out.println("admin123 -> " + DigestUtils.md5DigestAsHex("admin123".getBytes()));
        System.out.println("password -> " + DigestUtils.md5DigestAsHex("password".getBytes()));
        
        // 生成SQL更新语句
        System.out.println("\n=== SQL更新语句 ===");
        System.out.println("-- 更新密码为MD5格式");
        System.out.println("UPDATE user SET password = '" + DigestUtils.md5DigestAsHex("123456".getBytes()) + "' WHERE password = '123456';");
        System.out.println("UPDATE user SET password = '" + DigestUtils.md5DigestAsHex("admin123".getBytes()) + "' WHERE password = 'admin123';");
        
        // 验证前端加密是否一致
        System.out.println("\n=== 验证前端加密一致性 ===");
        System.out.println("如果前端MD5('123456') = e10adc3949ba59abbe56e057f20f883e");
        System.out.println("后端MD5('123456') = " + DigestUtils.md5DigestAsHex("123456".getBytes()));
        System.out.println("是否一致: " + "e10adc3949ba59abbe56e057f20f883e".equals(DigestUtils.md5DigestAsHex("123456".getBytes())));
    }
}